package com.example.vertification.service;

import com.example.vertification.entity.CartItem;
import com.example.vertification.entity.Question;
import com.example.vertification.entity.UserCartItems;
import com.example.vertification.repository.CartRepository;
import com.example.vertification.repository.QuestionRepository;
import com.example.vertification.repository.UserCartItemsRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CartService {
    private final CartRepository cartRepository;
    private final UserCartItemsRepository userCartItemsRepository;

    @Autowired
    public CartService(CartRepository cartRepository,UserCartItemsRepository userCartItemsRepository) {
        this.cartRepository = cartRepository;
        this.userCartItemsRepository = userCartItemsRepository;
    }



    public CartItem getCartItemByID(long cartId) {
        return cartRepository.findBycartID(cartId);
    }
    public List<CartItem> getAllCarts() {
        return cartRepository.findAll();
    }

    public List<UserCartItems> getAllCartsByUserID(long uid) {
        return userCartItemsRepository.findAllByuid(uid);
    }
    public UserCartItems getSingleCartItem(long id) {
        return userCartItemsRepository.findByexchangeid(id);
    }


    public void saveUserCartItem(UserCartItems i) {
        userCartItemsRepository.save(i);
    }



}